import 'package:flutter/material.dart';
import '../models/airplane_model.dart';

class StatusPanel extends StatelessWidget {
  final AirplaneModel model;
  final int batteryLevel;
  final int signalStrength;
  final double altitude;
  final double speed;
  final Map<String, String>? additionalInfo;

  const StatusPanel({
    super.key,
    required this.model,
    this.batteryLevel = 80,
    this.signalStrength = 90,
    this.altitude = 0.0,
    this.speed = 0.0,
    this.additionalInfo,
  });

  @override
  Widget build(BuildContext context) {
    return Container(
      padding: const EdgeInsets.all(12.0),
      decoration: BoxDecoration(
        color: Theme.of(context).colorScheme.primaryContainer.withOpacity(0.3),
        border: Border(
          bottom: BorderSide(
            color: Theme.of(context).colorScheme.primary.withOpacity(0.2),
            width: 1,
          ),
        ),
      ),
      child: Column(
        children: [
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceAround,
            children: [
              _buildStatusItem(
                context,
                Icons.battery_full,
                '$batteryLevel%',
                '电量',
                batteryLevel < 20 ? Colors.red : Colors.green,
              ),
              _buildStatusItem(
                context,
                Icons.signal_cellular_alt,
                '$signalStrength%',
                '信号',
                signalStrength < 30 ? Colors.red : Colors.green,
              ),
              _buildStatusItem(
                context,
                Icons.height,
                '${altitude.toStringAsFixed(1)}米',
                '高度',
                null,
              ),
              _buildStatusItem(
                context,
                Icons.speed,
                '${speed.toStringAsFixed(1)}米/秒',
                '速度',
                null,
              ),
            ],
          ),
          
          // 显示额外信息
          if (additionalInfo != null && additionalInfo!.isNotEmpty)
            Padding(
              padding: const EdgeInsets.only(top: 8.0),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: additionalInfo!.entries.map((entry) {
                  return Padding(
                    padding: const EdgeInsets.symmetric(horizontal: 12.0),
                    child: _buildStatusItem(
                      context,
                      Icons.info_outline,
                      entry.value,
                      entry.key,
                      null,
                    ),
                  );
                }).toList(),
              ),
            ),
        ],
      ),
    );
  }

  Widget _buildStatusItem(
    BuildContext context,
    IconData icon,
    String value,
    String label,
    Color? iconColor,
  ) {
    return Column(
      mainAxisSize: MainAxisSize.min,
      children: [
        Icon(
          icon,
          color: iconColor ?? Theme.of(context).colorScheme.primary,
          size: 20,
        ),
        const SizedBox(height: 4),
        Text(
          value,
          style: Theme.of(context).textTheme.bodyMedium?.copyWith(
                fontWeight: FontWeight.bold,
              ),
        ),
        Text(
          label,
          style: Theme.of(context).textTheme.bodySmall,
        ),
      ],
    );
  }
} 